<?php
namespace Home\Controller;
class PersonController extends BaseController {
    public function changePwd() {
        if (IS_POST) {
            $where['id'] = $this->userinfo['id'];
            $pwd = I('post.passwd');
            empty($pwd) && $this->error('非法操作，请输入要修改的密码');
            $data['upass'] = md5($pwd);
            if (D('User')->changePwd($where, $data)) {
               $this->success('密码修改成功', U('Person/changePwd'));
               exit();
            } else {
                $this->error('修改失败', U('Person/changePwd'));
            } 
        }
        $this->display();
    }
    public function addSignature() {
        if (IS_POST) {
            $data['uid'] = $this->userinfo['id'];
            $signature = I('post.signature');
            empty($signature) && $this->error('非法操作，请输入要添加的签名');
            $data['signature'] = $signature;
            if (D('Signature')->addNature($data)) {
               S('signature_'.$this->userinfo['id'], null);
               $this->success('签名添加成功', U('Person/addSignature'));
               exit();
            } else {
                $this->error('签名添加失败', U('Person/addSignature'));
            } 
        }
        $this->display();
    }
    
    public function seeSendMsg() {
        $where['uid'] = $this->userinfo['id'];
        $log = D('log');
        $count      = $log->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,C('PAGE_LIST'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig("prev", "上一页");
        $Page->setConfig("next", "下一页");
        $Page->setConfig("theme", "%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $limit = $Page->firstRow.','.$Page->listRows;
        $this->logData = $log->getLogs($where, $limit);
        $this->page = $Page->show();
        $this->display();
    }
    
    public function detail() {
        $where['id'] = intval(I('get.lid'));
        $where['uid'] = $this->userinfo['id'];
        $log = D('Log');
        $loginfo = $log->getOneLog($where);
        $loginfo['mobiles'] = explode(',', $loginfo['mobiles']);
        $res = explode(':', $loginfo['status']);
        if ($res[0] = 'success') {
            $loginfo['status'] = '提交成功';
        }
        $this->logs = $loginfo;
        $this->display();
    }
}
